/*	
	This is a arma 3 function script used for ArmA 3 Afterlife Mod
	(C) ArmACN Afterlife Mod DEV Team
	www.afterlifemod.com
	
	Function : ExileServer_object_vehicle_network_addLockRequest
*/
private["_sessionID","_package","_objectNetID","_pinCode","_ownerUID","_vehicle","_playerLevel","_requireLevel","_playerObject","_vehicleClassName","_interactionVehicle","_lockedVehicle"];
_sessionID = _this select 0;
_package = _this select 1;
_objectNetID = _package select 0;
_pinCode = _package select 1;
_playerLevel = _package select 2;
_interactionVehicle = _package select 3;

_playerObject = _sessionID call ExileServer_system_session_getPlayerObject;
_ownerUID = getPlayerUID _playerObject;
_vehicle = objectFromNetId _objectNetID;
_vehicleClassName = typeOf _vehicle;
_requireLevel = getNumber (missionConfigFile >> "CfgAfterlifeVehicle" >> _vehicleClassName >> "level");

if !(isClass (missionConfigFile >> "CfgAfterlifeVehicle" >> _vehicleClassName))exitWith
{
	[_sessionID, "toastRequest", ["ErrorTitleAndText", ["抱歉!","你能对这辆载具上锁"]]] call ExileServer_system_network_send_to;
};

if !(alive _playerObject)exitWith
{
	[_sessionID, "toastRequest", ["ErrorTitleAndText", ["抱歉!","你不是一个活人"]]] call ExileServer_system_network_send_to;
};

if (_playerLevel < _requireLevel)exitWith
{
	[_sessionID, "toastRequest", ["WarningTitleAndText", ["抱歉!",format ["你至少需要达到 %1 级才能给这辆载具上锁", _requireLevel]]]] call ExileServer_system_network_send_to;
};

if !(_vehicle isKindOf "AIR" || _vehicle isKindOf "CAR" || _vehicle isKindOf "BOAT")exitWith
{
	[_sessionID, "toastRequest", ["ErrorTitleAndText", ["抱歉!","这并不是一辆载具"]]] call ExileServer_system_network_send_to;
};

if (_vehicle getVariable ["ExileIsPersistent", true])exitWith
{
	[_sessionID, "toastRequest", ["ErrorTitleAndText", ["抱歉!","这辆载具已经被人上了锁"]]] call ExileServer_system_network_send_to;
};

if !(isNil {_vehicleObj getVariable "SC_drivenVehicle"})exitWith
{
	[_sessionID, "toastRequest", ["ErrorTitleAndText", ["抱歉!","这辆载具是属于服务器的"]]] call ExileServer_system_network_send_to;
};

if !(count _pinCode == 4)exitWith
{
	[_sessionID, "toastRequest", ["WarningTitleAndText", ["抱歉!","你需要一个4位数的密码"]]] call ExileServer_system_network_send_to;
};

_playerObject removeMagazineGlobal "Exile_Item_CodeLock";

_vehicle setVariable ["ExileOwnerUID", _ownerUID];
_vehicle setVariable ["ExileAccessCode", _pinCode];
_vehicle setVariable ["ExileIsPersistent", true];
_vehicle setVariable ["ExileIsLocked",-1];

_vehicle call ExileServer_object_vehicle_database_insert;
_vehicle call ExileServer_object_vehicle_database_update;

[owner _vehicle,"LockVehicleRequest",[netId _vehicle,true]] call ExileServer_system_network_send_to;

[_sessionID, "toastRequest", ["SuccessTitleAndText", ["成功!","你成功的给这辆载具上了锁"]]] call ExileServer_system_network_send_to;